<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <!--        type 0 学生 2 职工-->
        <span>游园项目管理</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="mb-10">
          <el-button size="small" plain type="primary" @click="handleEdit(0)">新增游园子项目</el-button>
          <el-button size="small" plain @click="InitFn()">重置数据</el-button>
        </div>
        <!--本体列表，数据 -->
        <div class="table-body">
          <div class="table-body-box">
            <el-table
                ref="multipleTable"
                :data="arryList"
                border
                :height="tableHeight"
                v-loading="loading"
                tooltip-effect="dark"
                style="width: 100%"
                header-cell-class-name="table-text-c"
                cell-class-name="table-text-c">
              <el-table-column
                  prop="title"
                  label="项目名称"
                  :key="1">
              </el-table-column>
              <el-table-column
                  label="负责人"
                  :key="2">
                <template slot-scope="scope">
                  {{ scope.row.user ? scope.row.user.realname : '' }}
                </template>
              </el-table-column>
              <el-table-column
                  label="签到人数"
                  :key="3">
                <template slot-scope="scope">
                  <el-button size="small" plain @click="inType=2,itemId=scope.row.id,userVisible=true">{{scope.row.sign_number}}</el-button>
                </template>
              </el-table-column>
              <el-table-column
                  label="未签到签到人数"
                  :key="4">
                <template slot-scope="scope">
                  <el-button size="small" plain @click="inType=3,itemId=scope.row.id,userVisible=true">
                    {{userNumber - scope.row.sign_number}}</el-button>
                </template>
              </el-table-column>

              <el-table-column
                  prop="create_time"
                  label="操作"
                  width="260"
                  :key="5">
                <template slot-scope="scope">
                  <el-button size="small" @click="handleShowQrcode(scope.row.id)">项目二维码</el-button>
                  <el-button size="small" @click="handleEdit(scope.row.id)">编辑</el-button>
                  <el-button type="danger" size="small" @click="handleDetel(scope.row.id)" plain>删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">确定</el-button>
      </div>
    </div>
    <addProject :visible.sync="editVisible" :detailId="itemId" :parentsId="detailId" @InitFn="InitFn"></addProject>
    <comeUserList :visible.sync="userVisible" :detailId="itemId" :inType="inType"></comeUserList>
    <childQrcode :visible.sync="qrcodeVisible" :detailId="itemId"></childQrcode>
  </div>
</template>

<script>
import {pagination} from '@/utils/util.js'
import {garden_party_option_index, garden_party_option_delete, garden_party_Detail} from '@/api/admin/school'
import addProject from "./addProject";
import comeUserList from "./comeUserList";
import childQrcode from "./childQrcode";

export default {
  props: ['visible', 'detailId'], // listType 1 签收 2 未签收
  components: {addProject, comeUserList, childQrcode},
  data() {
    return {
      dialogVisible: false,
      arryList: [], // 数据列表
      // 页数
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      tableHeight: 0,
      editVisible: false,
      itemId: 0,
      userVisible: false,
      loading: true,
      qrcodeVisible: false,
      userNumber: 0,
      inType: 0
    }
  },
  watch: {
    visible() {
      if (this.visible) {
        let n = this;
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;
          this.tableHeight = height - (51 + 20 + 43 + 51)
        })
        this.InitFn()
        this.getDetailFn()
      } else {
        this.arryList = [];
        this.page.pageindex = 1
        this.page.total = 0
      }
      this.dialogVisible = this.visible
    }
  },
  created() {
  },
  methods: {
    // 初始化
    InitFn() {
      let n = this
      this.loading = true
      let data_ = {}
      data_.garden_party_id = this.detailId
      data_.p = this.page.pageindex
      garden_party_option_index(data_).then(res => {
        if (!res.code) {
          console.log('res:', res)
          this.arryList = res.list.data
          this.page.total = res.list.total
        }
        n.loading = false
      })
    },
    getDetailFn(){
      garden_party_Detail({id: this.detailId}).then(res => {
        console.log('res:', res)
        let data_ = JSON.parse(JSON.stringify(res.vo))
        this.userNumber = data_.number
      })
    },
    handleShowQrcode(id) {
      this.itemId = id
      this.qrcodeVisible = true
    },
    // 编辑
    handleEdit(row) {
      this.itemId = row
      this.editVisible = true
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    handleDetel(id) {
      this.$confirm('确认删除该项目，是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        garden_party_option_delete({id: id}).then(res => {
          if (!res.code) {
            this.$message.success(res.msg)
            this.InitFn()
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
      })
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}

.hearder-search {
  display: flex;
  align-items: center;
}

.breadcrumb-container {
  margin-bottom: 10px;
}

.parentsList p {
  background: #f8f8f8;
  margin-bottom: 5px;
}

.parentsList p:last-child {
  margin-bottom: 0;
}
</style>


